<?php
namespace PsiFramework\Applications\DefaultApp\Classes\DAO;

use PsiFramework\Classes\Util\Database\Query\SqlTable;

use PsiFramework\Classes\Util\Database\Builder\QueryBuilder;

use PsiFramework\Classes\Util\Database\Query\SqlValue;

use PsiFramework\Classes\Util\Database\Query\SqlColumn;

use PsiFramework\Classes\Util\Database\Query\SqlOperation;

import("Classes.DAO.AbstractDAO");
import("Applications.DefaultApp.Classes.Model.Trace");

use \PsiFramework\Classes\DAO\AbstractDAO;
use \PsiFramework\Classes\Util\Parameters\ObjectParameters;
use \PsiFramework\Applications\DefaultApp\Classes\Model\Trace;

/**
 * PsiFramework
 * Php Simple Framework
 *
 * @author Rémi San
 * @version beta
 */

/**
 * The TraceDAO is the Data Access Object for the class Trace
 *
 * @package DAO
 */
class TraceDAO extends AbstractDAO
{

    protected static $_singleton = null;

    public function deleteUserTraces($user)
    {
        $queryBuilder = new QueryBuilder();
        $queryBuilder->createDeleteQuery();
        
        $table = new SqlTable(
            $this->_objectParameters->getTable(),
            $this->_objectParameters->getSchema()
        );
        $queryBuilder->setTable($table);
        
        $userId = $user->getId();
        
        $operation = new SqlOperation(SqlOperation::$equal);
        $operation->addParameter(new SqlColumn('user_id')); 
        $operation->addParameter(new SqlValue($userId));
        
        $queryBuilder->addWhereClause($operation);
        $result = $this->_database->executeQuery(
            $queryBuilder->buildQuery()
        );
    }
    
    /**
     * Function to be called instead of the constructor.
     *
     * @param ObjectParameters $objectParameters The object parameters
     *
     * @return TraceDAO instance
     */
    public static function getInstance(ObjectParameters $objectParameters)
    {

        if (self::$_singleton==null) {
            self::$_singleton = new TraceDAO($objectParameters);
        }

        return self::$_singleton;
    }

}
